package com.iretailer.report.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iretailer.report.dto.PageResult;
import com.iretailer.report.dto.QueryOption;
import com.iretailer.report.mapper.PageWidgetCompanyMapper;
import com.iretailer.report.model.PageWidgetCompany;
import com.iretailer.report.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: xjw
 * @Date: 2019/1/30 10:41
 * @Description:
 */
@Service
public class PageWidgetCompanyService {
    @Autowired
    private PageWidgetCompanyMapper pageWidgetCompanyMapper;


    public PageResult<PageWidgetCompany> selectPageByIsModel_Title(Integer isMobile, String title, QueryOption queryOption) {

        Page page = new Page<PageWidgetCompany>(1, Long.MAX_VALUE);
        QueryWrapper<PageWidgetCompany> queryWrapper = new QueryWrapper<PageWidgetCompany>();
        queryWrapper.eq("1", 1);
        if (isMobile != null) {
            queryWrapper.eq("mobile", isMobile);
        }
        if (title != null) {
            queryWrapper.like("title", title);
        }
        queryOption.judge(page, queryWrapper);
        queryWrapper.orderByAsc("Ranked");
        pageWidgetCompanyMapper.selectPage(page, queryWrapper);

        return new PageResult<>(page.getTotal(), page.getRecords());
    }
}
